﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;

namespace PuanYonetimi
{
    public partial class frmLogin : DevExpress.XtraEditors.XtraForm
    {
        public bool AdminMode { get; set; }

        public frmLogin()
        {
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            KullaniciGiris();
        }

        private void KullaniciGiris()
        {
            if (cmbKullanici.SelectedIndex > -1)
            {
                Kullanici usr = (Kullanici)((ComboItem)cmbKullanici.SelectedItem).Value;
                if (usr.Sifre == txtSifre.Text)
                {
                    AdminMode = usr.Admin;
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Hatalı Şifre");
                }
            }
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            try
            {
                using (PromoEntities ent = new PromoEntities())
                {
                    cmbKullanici.Properties.Items.AddRange(ent.Kullanicilar.Select(x => new ComboItem() { Text = x.Adi, Value = x }).ToArray());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void txtSifre_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                KullaniciGiris();
            }
        }
    }
}